package oj;

//反转链表：给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
public class Solution_206 {
    public static ListNode reverseList(ListNode head){
        ListNode prev = null;
        ListNode cur = head;
        while (cur != null){
            ListNode next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }

    public static void main(String[] args) {
        ListNode n1 = new ListNode(100);
        ListNode n2 = new ListNode(200);
        ListNode n3 = new ListNode(300);
        ListNode n4 = new ListNode(400);
        ListNode n5 = new ListNode(500);
        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        n4.next = n5;
        n5.next = null;
        Solution_206 solution = new Solution_206();
        ListNode ans = solution.reverseList(n1);
    }
}
